package com.zjuee.web.ledger.controller;

import com.zjuee.base.bean.response.R;
import com.zjuee.base.constant.Common;
import com.zjuee.base.dto.common.login.LoginDto;
import com.zjuee.base.valid.Insert;
import com.zjuee.base.valid.Update;
import com.zjuee.service.PlanPDeviceService;
import com.zjuee.service.PlanService;
import com.zjuee.base.model.common.plan.PlanPDevice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping(Common.Service.ZJUEE_CO_MAIN_PLAN_URL_PREFIX)
public class PlanPDeviceController{

    @Resource
    private PlanPDeviceService planPDeviceService;
    @Resource
    private PlanService planService;
    @Resource
    private LoginDto loginDto;

    /**
     * 新增计划生产设备信息 PlanPDevice
     *
     * @param planPDevice PlanPDevice
     * @return Long
     */
    @PostMapping("/p/device/addPlan")
    public R<Long> addPlanPDevice(@Validated(Insert.class) @RequestBody PlanPDevice planPDevice) {
        if(planPDevice.getWpiId()==null){
            return R.fail("计划ID为空！");
        }
        return R.ok(planPDeviceService.add(planPDevice));
    }

    /**
     * 修改计划生产设备信息 PlanPDevice
     *
     * @param planPDevice PlanPDevice
     * @return Boolean
     */
    @PutMapping("/p/device/update")
    public R<Boolean> updatePlanPDevice(@Validated(Update.class) @RequestBody PlanPDevice planPDevice) {
        if(planPDevice.getWpiId()==null){
            return R.fail("计划ID为空！");
        }
        return R.ok(planPDeviceService.update(planPDevice));
    }

//     
//    public R<Boolean> deletePlanPDevice(@NotNull Long id, @NotNull String wpiYear) {
//        Boolean type = false;
//        if (wpiYear.equals(DateUtils.getYear(new Date()))) {
//            type = planPDeviceService.delete(id, loginDto.getPlanId());
//        } else {
//            PlanInfo plan = planService.selectInfoByBciId(loginDto.getOrgBusinessId(), wpiYear);
//            if (plan != null) {
//                type = planPDeviceService.delete(id, plan.getId());
//            } else {
//                return R.fail("删除产设备基本信息失败");
//            }
//        }
//        if (type) {
//            return R.ok("success");
//        }
//        return R.fail("删除产设备基本信息失败");
//    }
}
